import { defineStore } from "pinia"

import {
  getHomeCategories,
  getHomeHotSuggests,
  getHouseList,
} from "@/services/modules/home"

export const useHomeData = defineStore("home", {
  state() {
    return {
      homeHotSuggets: [],
      categories: [],
      houseList: [],
      currentPage: 1,
    }
  },
  actions: {
    async fetchHotSuggestsData() {
      const res = await getHomeHotSuggests()
      this.homeHotSuggets = res.data
    },
    async fetchCategoriesData() {
      const res = await getHomeCategories()
      this.categories = res.data
    },
    async fetchHouseListData() {
      const res = await getHouseList(this.currentPage)
      this.houseList.push(...res.data)
      this.currentPage++
      // console.log(this.currentPage);
    },
  },
})
